﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace _011
{
    /// <summary>
    /// 堆栈示例
    /// 后进先出
    /// </summary>
    internal class Program
    {
        static void Main(string[] args)
        {
            Stack st = new Stack();
            st.Push('A');
            st.Push('B');
            st.Push('C');
            st.Push('D');

            Console.WriteLine("当前堆栈中的元素：");
            foreach(char c in st)
            {
                Console.Write(c + " ");
            }
            Console.WriteLine();

            st.Push('E');
            st.Push('F');
            Console.WriteLine("堆栈中下一个弹出的值是：\r\n{0}",st.Peek());
            Console.WriteLine("当前堆栈中的元素：");
            foreach (char c in st)
            {
                Console.Write(c + "");
            }
            Console.WriteLine();

            Console.WriteLine("删除值下面的值：");
            Console.Write(st.Pop() + " ");
            Console.Write(st.Pop() + " ");
            Console.Write(st.Pop() + " " + "\r\n");//"\r\n"的意思是回车换行符
            Console.WriteLine("当前堆栈中的元素："); 
            foreach (char c in st)
            {
                Console.Write(c + " ");
            }
            Console.ReadKey();
        }
    }
}
